#ifndef _MENU_
#define _MENU_

#include "GUI.h"

//VGUI:
VGui Menu;
//Controls:
VGuiButton BPlay;
VGuiButton BTrainE;
VGuiButton BTrainH;
VGuiButton BFScreen;
VGuiButton BExit;
VGuiButton BOnLine;
VGuiButton BHost;
VGuiButton BJoin;
VGuiButton BReturn;
VGuiLabelEntry LEServerIP;

bool Play(){SetGameMode(MODE_HUMANVSHUMAN); return true;}
bool TrainE(){SetGameMode(MODE_TRAINING_NORMAL); return true;}
bool TrainH(){SetGameMode(MODE_TRAINING_HARD); return true;}
bool FullScreen()
{
	bool WS = hge->System_GetState(HGE_WINDOWED);
	hge->System_SetState(HGE_WINDOWED,!WS); 
	
	// Bug of cursor weird texture:
	SetCursorPos(GAME_WIDTH/2,GAME_HEIGHT/2);

	BExit.Visible = WS;
	return true;
}

bool Exit(){IsExiting = true; return true;}
bool OnLine()
{
	BHost.Visible = true;
	BJoin.Visible = true;
	BReturn.Visible = true;
	LEServerIP.Visible = true;
	BPlay.Visible = BTrainE.Visible = BTrainH.Visible = BFScreen.Visible = BOnLine.Visible = false;
	return true;
}
bool Return()
{
	BHost.Visible = false;
	BJoin.Visible = false;
	BReturn.Visible = false;
	LEServerIP.Visible = false;
	BPlay.Visible = BTrainE.Visible = BTrainH.Visible = BFScreen.Visible = BOnLine.Visible = true;
	CloseServer();
	LEServerIP.Enabled = true;
	BJoin.Enabled = true;
	LEServerIP.SetText("127.0.0.1");
	return true;
}
bool Host()
{
	if (!InitServer())
		return false;
	LEServerIP.SetText("Waiting player");
	LEServerIP.Enabled = false;
	BJoin.Enabled = false;
	Player * P2 = (Player*)Player2Pointer;
	P2->SetKeyboardControlled(false);
	return true;
}
bool Join(){Player * P1 = (Player*)Player1Pointer;P1->SetKeyboardControlled(false);return JoinServer(LEServerIP.GetText());}
void InitMenu()
{
	//Menu init:
	Menu.SetBackG("VGUI\\bg.zbs");
	Menu.SetCursor("VGUI\\cursor.zbs");

	//BPlay init:
	Menu.AddCtrl((void*)&BPlay);
	BPlay.SetPosition(b2Vec2(400,500));
	BPlay.OnClick = &Play;
	BPlay.SetTitle("Play");

	//BTrainE init:
	Menu.AddCtrl((void*)&BTrainE);
	BTrainE.SetPosition(b2Vec2(400,300));
	BTrainE.OnClick = &TrainE;
	BTrainE.SetTitle("Easy Training");

	//BTrainH init:
	Menu.AddCtrl((void*)&BTrainH);
	BTrainH.SetPosition(b2Vec2(400,100));
	BTrainH.OnClick = &TrainH;
	BTrainH.SetTitle("Hard Training");
	
	//BFScreen init:
	Menu.AddCtrl((void*)&BFScreen);
	BFScreen.SetPosition(b2Vec2(600,300));
	BFScreen.OnClick = &FullScreen;
	BFScreen.SetTitle("FullScreen");
	
	//BExit init:
	Menu.AddCtrl((void*)&BExit);
	BExit.SetPosition(b2Vec2(100,100));
	BExit.OnClick = &Exit;
	BExit.SetTitle("Exit");
	BExit.Visible = false;
	
	//BOnLine init:
	Menu.AddCtrl((void*)&BOnLine);
	BOnLine.SetPosition(b2Vec2(100,500));
	BOnLine.OnClick = &OnLine;
	BOnLine.SetTitle("On-Line");

	//BReturn init:
	Menu.AddCtrl((void*)&BReturn);
	BReturn.SetPosition(b2Vec2(600,100));
	BReturn.OnClick = &Return;
	BReturn.SetTitle("Return to main");
	BReturn.Visible = false;

	//BJoin init:
	Menu.AddCtrl((void*)&BJoin);
	BJoin.SetPosition(b2Vec2(400,300));
	BJoin.OnClick = &Join;
	BJoin.SetTitle("Join server");
	BJoin.Visible = false;

	//BHost init:
	Menu.AddCtrl((void*)&BHost);
	BHost.SetPosition(b2Vec2(400,500));
	BHost.OnClick = &Host;
	BHost.SetTitle("Host server");
	BHost.Visible = false;

	//LEServerIP init:
	Menu.AddCtrl((void*)&LEServerIP);
	LEServerIP.SetPosition(b2Vec2(100,300));
	LEServerIP.SetText("127.0.0.1");
	LEServerIP.SetPermitedKeys("0123456789.");
	LEServerIP.Align = 0;
	LEServerIP.Visible = false;
}



#endif
